<template>
  <div class="deadline">
    <h3 class="section-title">与子相期,不负君意</h3>
    <div class="section-description">
      <p>
        “当你老了，回顾一生，就会发觉：什么时候出国读书，什么时候决定做第一份职业、何时选定了对象而恋爱、什么时候结婚，其实都是命运的巨变。只是当时站在三岔路口，眼见风云千樯，你作出选择的那一日，在日记上，相当沉闷和平凡，当时还以为是生命中普通的一天。”
        ——陶杰《杀鹌鹑的少女》
      </p>
    </div>
    <div class="section-preview">
      <div class="container hide-on-tablet">
        <span class="path-line--gradient"></span>
      </div>
      <div v-for="item of articles" :key="item.title" class="deadline-item">
        <div class="deadline-item-graphic">
          <div class="deadline-item-graphic--inner">
            <div class="deadline-item-graphic--wrapper">
              <div class="deadline-item-graphic--content">
                <div 
                  v-for="line in item.todos"
                  :key="line.key" 
                  :class="['todo',line.value === 1 ? 'todo--working' : '', line.value === 2 ? 'todo--done' : '']">
                  <div class="todo__header">
                    <span><i class="sight-icon-calendar"></i> {{ formatDate(line.dateStart) }} - {{ formatDate(line.dateEnd) }}</span>
                  </div>
                  <div class="todo__body">
                    <div class="todo__content">
                      <div>{{ line.key }}</div>
                    </div>
                    <div class="todo__state">
                      <i 
                        :class="{
                          'sight-icon-x-square':line.value === 0,
                          'sight-icon-check-square':line.value === 2,
                          'sight-icon-square':line.value === 1
                        }"
                      ></i>
                    </div>
                  </div>  
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="deadline-item-line">
          <span class="path-circle"></span>
          <span class="path-line"></span>
        </div>
        <div class="deadline-item-description">
          <div class="deadline-item-description--inner">
            <h5 class="small-heading">{{item.slug}}</h5>
            <div class="deadline-item-description--body">
              <p class="paragraph paragraph-medium">
                {{item.description}}
              </p>
            </div>
          </div>
        </div>
      </div>
      <div class="section-label">
        <div class="section-label--text">start</div>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from 'dayjs'
export default {
  name: 'Deadline',
  async asyncData({ $content }) {
    const articles = await $content('todos').sortBy('createdAt','desc').fetch()
    return {
      articles
    }
  },
  head() {
    return {
      title: '不要干等决定性时刻的到来',
    }
  },
  methods:{
    formatDate(date) {
      return dayjs(date).format('YYYY MM/DD')
    },
  }
}
</script>
<style scoped lang="scss">
.deadline {
  margin-top: var(--space-16x);
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  width: calc(var(--page-width-with-margin) + var(--gap-double) * 2);
  padding-left: var(--page-margin);
  padding-right: var(--page-margin);
}
.section-title {
  text-align: center;
  margin: 0 0 var(--gap);
  padding-bottom: var(--gap-half);
  letter-spacing: -0.05em;
}
.section-description {
  max-width: 45rem;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
  padding-bottom: var(--gap-quarter);
  margin-bottom: var(--space-16x);
}
.path-line--gradient {
  --start-color: var(--background);
  --end-color: var(--accents-3);

  width: 1px;
  align-self: center;
  height: 100px;
  background: linear-gradient(var(--start-color), var(--end-color));
  padding-right: 1px;
}
.deadline-item {
  display: flex;
  align-items: top;
  width: 100%;
}

.deadline-item-graphic {
  flex: 1 1;
  margin: var(--gap-double) 0;
  border-radius: 15px;
}
.deadline-item-graphic--inner {
  padding-right: var(--space-16x);
}
.deadline-item-graphic--wrapper {
  transform: translateY(-50%);
}
.deadline-item-graphic--content {
  width: 100%;
  padding: var(--space-4x);
  box-shadow: var(--shadow-smallest);
  display: flex;
  align-items: center;
  border-radius: 8px;
  flex-wrap: wrap;
}
.todo{
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--space-4x);
  color: var(--accents-7);
  border-bottom: 1px solid var(--accents-2);
  .todo__header{
    display: flex;
    justify-content: space-between;
    font-size: 0.75em;
  }
  .todo__body{
    margin-top: var(--space-4x);
    display: flex;
    align-items: center;
    font-size: 0.875em;
  }
  .todo__state{
    width: 1.5em;
    height: 1.5em;
    text-align: center;
    line-height: 1.5em;
    font-size: 16px;
  }
  .todo__content{
    flex: 1;
  }
  &--done{
    color: var(--accents-3);
  }
  &--working{
    color: var(--accents-5);
  }
}
.deadline-item-line {
  display: flex;
  flex-direction: column;
}
.path-circle {
  width: 11px;
  height: 11px;
  box-shadow: 0 0 0 1.5px var(--accents-3) inset;
  border-radius: 50%;
}
.path-line {
  --dotted-color: var(--accents-3);

  border-right: 1px dashed var(--dotted-color);
  width: 1px;
  align-self: center;
  flex: 1 1;
}
.path-line--end {
  --start-color: var(--accents-3);
  --end-color: var(--violet-dark);

  flex: 1 1;
  width: 1px;
  align-self: center;
  height: 100px;
  background: linear-gradient(var(--start-color), var(--end-color));
  padding-right: 1px;
}
.deadline-item-description {
  flex: 1 1;
}
.deadline-item-description--inner {
  padding-left: calc(var(--space-16x) - 5px);
  padding-right: var(--gap-double);
  margin-top: var(--space-gap-quarter-negative);
  padding-bottom: var(--space-64x);
  margin-bottom: var(--gap);
}
.small-heading {
  font-size: 1.5rem;
  letter-spacing: -0.05em;
  margin: 0 0 var(--gap-half);
}
.deadline-item-description--body {
  color: var(--accents-5);
}
.section-label {
  text-align: center;
  margin-bottom: var(--space-4x);
}
.section-label--text {
  --start-color: var(--violet-dark);
  --end-color: var(--foreground);

  display: inline-flex;
  border-radius: 100%;
  color: var(--background);
  font-size: 0.875rem;
  width: 45px;
  height: 45px;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin-bottom: var(--gap);
  background: linear-gradient(90deg, var(--start-color), var(--end-color));
}
@media screen and (max-width: 900px) {
  .deadline-item-graphic--inner {
    padding: 0;
  }
  .deadline-item-graphic--wrapper {
    transform: translateY(0);
  }
  .deadline-item-description--inner {
    padding-bottom: var(--space);
    margin-top: var(--space-8x);
  }
  .deadline-item {
    flex-direction: column;
  }
  .path-circle {
    margin: auto;
  }
  .deadline-item-graphic{
    order: 1;
  }
  .deadline-item-line {
    order: 2;
  }
  .path-line {
    flex: auto;
    height: 50px;
  }
  .path-line--end {
    flex: auto;
  }
}
</style>
